﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.RAL.FileDatabase;

namespace Empires.CRL.Logger
{
    public static class EmpiresLogger 
    {
        /// <summary>
        /// 记录错误
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        public static void ErrorLog(string message,string logger) 
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Error"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", String.Empty));
        }
        /// <summary>
        /// 记录错误
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        /// <param name="ex"></param>
        public static void ErrorLog(string message,string logger, Exception ex) 
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Error"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", ex.ToString()));
        }
        /// <summary>
        /// 记录警告
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        public static void WarnLog(string message, string logger)
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Warn"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", string.Empty));
        }
        /// <summary>
        /// 记录警告
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        /// <param name="ex"></param>
        public static void WarnLog(string message,string logger, Exception ex)
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Warn"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", ex.ToString()));
        }
        /// <summary>
        /// 记录操作失败信息
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        public static void FatalLog(string message, string logger)
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Fatal"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", string.Empty));
        }
        /// <summary>
        /// 记录操作失败信息
        /// </summary>
        /// <param name="message">错误信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        /// <param name="ex"></param>
        public static void FatalLog(string message,string logger, Exception ex)
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Fatal"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", ex.ToString()));
        }
        /// <summary>
        /// 记录程序报告
        /// </summary>
        /// <param name="message">报告信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        public static void InfoLog(string message, string logger) 
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Info"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", string.Empty));
        }
        /// <summary>
        /// 记录程序报告
        /// </summary>
        /// <param name="message">报告信息</param>
        /// <param name="logger">记录者，通常是发生错误的类名</param>
        /// <param name="ex"></param>
        public static void InfoLog(string message,string logger, Exception ex) 
        {
            SQLiteProvider sqlite = new SQLiteProvider();
            sqlite.SetConnectString(System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString);
            sqlite.ExecuteNonQuery("insert into ErrorLog ([dtDate],[sLevel],[sLogger],[sMessage],[sException]) VALUES (@log_date, @log_level, @logger, @message, @exception)",
                new KeyValuePair<string, string>("@log_date", DateTime.Now.ToString()),
                new KeyValuePair<string, string>("@log_level", "Info"),
                new KeyValuePair<string, string>("@logger", logger),
                new KeyValuePair<string, string>("@message", message),
                new KeyValuePair<string, string>("@exception", ex.ToString()));
        } 
     
    }
}
